home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 43
/
Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso
/
-serious-
/
programming
/
arexx
/
eqfiles
/
eqfiles.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1999-06-14
|
13KB
|
440 lines
/* $VER: EqFiles.rexx 2.2 (30.05.99)
*/
/* Filenames of external programs */
/*
cmp='HD0:OTHER/C/Cmp'
*/
/* If the routine does not find external program(s), uncomment the line(s) above and insert your path(s) */
/* Initialization */
address command
curdir=pragma('D')
if right(curdir,1)=':' ^ right(curdir,1)='/' then curpath=curdir
else curpath=curdir||'/'
call open('STDERR','NIL:','write')
'Delete >NIL: T:EqFiles_#? FORCE'
signal on break_c
/* Parsing routine */
say ' pParsing input string...F'
parse arg instring
if instring=='?' then signal template
do i=1 to 10
quote1=pos('"',instring)
select
when quote1=0 then parse var instring arg.i remainder
when quote1=1 then do
quote2=pos('"',instring,2)
select
when quote2=0 then signal error1
when quote2=2 then do
if substr(instring,3,1)~=' ' then signal error2
parse var instring arg.i remainder
end
otherwise do
if substr(instring,quote2+1,1)~=' ' then signal error2
parse var instring '"'arg.i'"' remainder
end
end
end
otherwise do
if substr(instring,quote1-1,1)~=' ' then signal error2
parse var instring arg.i remainder
end
end
instring=strip(substr(remainder,2),'L')
end
/* Input check routine */
optdir1=''
optdir2=''
optall=''
optdel=''
optndl=''
optfil=''
opticn=''
optthr=''
inpat=''
expat=''
optpat=''
threshold=0
do i=1 to 10
option=upper(arg.i)
select
when option=='' then leave
when option='ALL' then do
optall=option||' '
arg.i=''
end
when option='DELETE' then do
optdel=option||' '
arg.i=''
end
when option='NODL' then do
optndl=option||' '
arg.i=''
end
when option='FILES' then do
optfil=option||' '
arg.i=''
end
when option='ICONS' then do
opticn=option||' '
arg.i=''
end
when left(option,5)='SIZE>' then do
optthr=option
arg.i=''
end
when left(option,6)='INPAT=' then do
inpat=substr(arg.i,7)
arg.i=''
end
when left(option,6)='EXPAT=' then do
expat=substr(arg.i,7)
arg.i=''
end
when optdir1=='' then do
optdir1=arg.i
arg.i=''
end
when optdir2=='' then do
optdir2=arg.i
arg.i=''
end
otherwise nop
end
end
select
when optdir1=='' then signal error3
when optdir1=='""' then dir1=curpath
otherwise do
'Dir >NIL: "'optdir1'" Dirs'
if RC=20 then signal error4
colon=pos(':',optdir1)
if colon=0 then dir1=curpath||optdir1
else do
expdir1=pragma('D',pragma('D',left(optdir1,colon)))
if right(expdir1,1)~=':' then expdir1=expdir1||'/'
dir1=expdir1||substr(optdir1,colon+1)
end
end
end
select
when optdir2=='' then dir2=dir1
when optdir2=='""' then dir2=curpath
otherwise do
'Dir >NIL: "'optdir2'" Dirs'
if RC=20 then signal error5
colon=pos(':',optdir2)
if colon=0 then dir2=curpath||optdir2
else do
expdir2=pragma('D',pragma('D',left(optdir2,colon)))
if right(expdir2,1)~=':' then expdir2=expdir2||'/'
dir2=expdir2||substr(optdir2,colon+1)
end
end
end
do i=1 to 10
if arg.i~=='' then signal error6
end
if optthr~='' then do
threshold=right(optthr,length(optthr)-5)
if datatype(threshold,W)~=1 | threshold<0 then signal error7
optthr=optthr||' '
end
/* Pattern expansion routine */
nopat1=0
nopat2=0
dir1max=1
dir2max=1
dircheck=0
if exists(dir1)=1 then do
dir1=pragma('D',pragma('D',dir1))
if right(dir1,1)~=':' & right(dir1,1)~='/' then dir1=dir1||'/'
dir1.1=dir1
nopat1=1
end
else do
say 'Expanding patterns... F'
if right(dir1,1)~='/' then dir1=dir1||'/'
'Dir >T:EqFiles_DList1 "'dir1'" DIRS'
call open('in','T:EqFiles_DList1','read')
if seek('in',0,'E')=0 then signal error8
call seek('in',0,'B')
j=1
do i=1
line=readln('in')
if line='' then leave
dir1.i=strip(left(line,length(line)-6))
if right(dir1.i,1)~=':' & right(dir1.i,1)~='/' then dir1.i=dir1.i||'/'
if i>1 & dir1.j~==dir1.i then do
j=j+1
if j~=i then dir1.j=dir1.i
end
end
dir1max=j
call close('in')
end
if exists(dir2)=1 then do
dir2=pragma('D',pragma('D',dir2))
if right(dir2,1)~=':' & right(dir2,1)~='/' then dir2=dir2||'/'
dir2.1=dir2
nopat2=1
end
else if upper(dir1)~==upper(dir2) then do
say 'Expanding patterns... F'
if right(dir2,1)~='/' then dir2=dir2||'/'
'Dir >T:EqFiles_DList2 "'dir2'" DIRS'
call open('in','T:EqFiles_DList2','read')
if seek('in',0,'E')=0 then signal error8
call seek('in',0,'B')
j=1
do i=1
line=readln('in')
if line='' then leave
dir2.i=strip(left(line,length(line)-6))
if right(dir2.i,1)~=':' & right(dir2.i,1)~='/' then dir2.i=dir2.i||'/'
if i>1 & dir2.j~==dir2.i then do
j=j+1
if j~=i then dir2.j=dir2.i
end
end
dir2max=j
call close('in')
end
if dir1~==dir2 then do
if dir1max~=dir2max then dircheck=1
else do i=1 to dir1max
if dir1.i~==dir2.i then dircheck=1 ; leave
end
end
if inpat='' then inpat='#?'
select
when expat='' & opticn='' then expat='~(#?.INFO)'
when expat='' & opticn='ICONS ' then expat='#?'
when expat~='' & opticn='' then expat='~((#?.INFO)|('expat'))'
when expat~='' & opticn='ICONS ' then expat='~('expat')'
end
optpat='PAT="~(~('expat')|~('inpat'))"'
/* Data acquisition and preprocessing routine */
if dircheck=0 then comment='
Scanning
"'dir1
else comment='
Scanning
"'dir1'"
and
"'dir2
optfull=optall|| optdel||optndl||optfil||opticn||optthr||optpat
if optfull='' then say comment'"'
else say comment'"
with option(s) 'optfull'
'
say 'Acquiring data... F'
do i=1 to dir1max
'List >>T:EqFiles_FList "'dir1.i'" lformat="%8l 'dircheck' %p%n*"'dir1.i'" FILES 'optall optpat
if nopat1~=1 & optndl~='NODL' then say' <dir1> 'dir1.i' ...scanned'
end
call open('in','T:EqFiles_FList','read')
flen=seek('in',0,'E')
if flen=0 then signal error8
say 'Preprocessing data... F'
call seek('in',0,'B')
fnum1=-1
do until EOF('in')
call readln('in')
fnum1=fnum1+1
end
call close('in')
if dircheck=1 then do
say 'Acquiring data... F'
do i=1 to dir2max
'List >>T:EqFiles_FList "'dir2.i'" lformat="%8l 2 %p%n*"'dir2.i'" FILES 'optall optpat
if nopat2~=1 & optndl~='NODL' then say ' <dir2> 'dir2.i' ...scanned'
end
call open('in','T:EqFiles_FList','read')
if flen=seek('in',0,'E') then signal error9
say 'Preprocessing data... F'
call seek('in',flen+1,'B')
fnum2=-1
do until EOF('in')
call readln('in')
fnum2=fnum2+1
end
call close('in')
end
'Sort T:EqFiles_FList TO T:EqFiles_FList CASE'
/* Main routine */
pos=0
index=0
items=0
call open('in','T:EqFiles_FList','read')
call open('out','T:EqFiles_Result','write')
do forever
line1=readln('in')
if line1='' | index=fnum1 then leave
if substr(line1,10,1)='2' then iterate
else do
index=index+1
say 'Processing file 'index' of 'fnum1' in <dir1>F'
end
len1=left(line1,8)
if len1<=threshold then iterate
curpos=seek('in',0,'C')
do forever
line2=readln('in')
if line2='' then leave
if substr(line2,10,1)='1' then iterate
len2=left(line2,8)
if len2=len1 then do
fname1=substr(line1,12,pos('"',line1)-12)
fname2=substr(line2,12,pos('"',line2)-12)
if fname1~==fname2 & exists(fname1)=1 & exists(fname2)=1 then do
dpath1=substr(line1,pos('"',line1)+1)
dpath2=substr(line2,pos('"',line2)+1)
select
when abbrev(dpath1,dpath2)=1 then ineq=fname1<fname2
when abbrev(dpath2,dpath1)=1 then ineq=fname1>fname2
otherwise ineq=1
end
if ineq=1 then do
cmp '"'fname1'" "'fname2'" DUMP 0 CHECKD >NIL:'
if RC=0 then do
if optdel='DELETE ' then do
call writeln('out',fname1'
==
'fname2'
')
'Delete "'fname2'" FORCE QUIET'
end
else call writeln('out',fname1'
==
'fname2)
items=items+1
end
end
end
end
else leave
end
call seek('in',curpos,'B')
end
say ' p F'
call close('in')
call close('out')
/* Output routine */
if fnum1=1 then plural1=''
else plural1='s'
if fnum2=1 then plural2=''
else plural2='s'
if items=1 then do
plural=''
verb='has'
end
else do
plural='s'
verb='have'
end
if items~=0 then do
'Sort T:EqFiles_Result To T:EqFiles_Result'
'Type T:EqFiles_Result'
if dir1==dir2 then say '
'fnum1' file'plural1' found in <dir1>.
'
else say '
'fnum1' file'plural1' found in <dir1>; 'fnum2' file'plural2' found in <dir2>.
'
if optdel='DELETE ' then say '
'items' pair'plural' of equal files detected. Highlighted file'plural verb' been deleted.
'
else say '
'items' pair'plural' of equal files detected.
'
end
else do
if dir1==dir2 then say '
'fnum1' file'plural1' found in <dir1>.
'
else say '
'fnum1' file'plural1' found in <dir1>; 'fnum2' file'plural2' found in <dir2>.
'
say '
No equal files detected.
'
end
if optfil~='FILES ' then 'Delete T:EqFiles_#? QUIET'
else 'Delete T:EqFiles_FList QUIET'
exit
break_c:
say 'E
User break!
E p'
call close('in')
call close('out')
'Delete T:EqFiles_#? QUIET'
exit
error1:
say 'E
Illegal number of
"
delimiters!
E p'
exit
error2:
say 'E
Illegal use of
"
delimiters!
E p'
exit
error3:
say 'E
You must specify at least one directory!
E p'
exit
error4:
say 'FE
<dir1>
"'optdir1'"
not found: erroneous directory name/pattern!
E p'
exit
error5:
say 'FE
<dir2>
"'optdir2'"
not found: erroneous directory name/pattern!
E p'
exit
error6:
say 'E
Option
"'arg.i'"
not allowed!
E p'
exit
error7:
say 'E
Wrong
SIZE
specification!
E p'
exit
error8:
say 'E
No (allowed) files in directory
"'dir1'"
!
E p'
call close('in')
'Delete T:EqFiles_#? QUIET'
exit
error9:
say 'E
No (allowed) files in directory
"'dir2'"
!
E p'
call close('in')
'Delete T:EqFiles_#? QUIET'
exit
template:
say 'E
EqFiles V2.2 by Fulvio Peruggi - May 30, 1999
E'
say 'Usage: [rx] EqFiles[.rexx] [<dir1>] [<dir2>] [ALL] [DELETE] [NODL] [FILES]'
say ' [SIZE>x] [INPAT=y] [EXPAT=z] [ICONS]'
say 'EEqFiles scans all files in directories
<dir1>
and
<dir2>
, compares each'
say ' file in
<dir1>
with all files in
<dir2>
having the same size, and lists'
say ' all pairs of equal files.'
say '
<dir1>
and/or
<dir2>
can be explicit directory names or legal AmigaDOS'
say ' patterns. If
<dir2>
is not specified,
<dir2>
=
<dir1>
by default.'
say 'Command operations act on the files in all subdirectories of the given'
say ' directories if the optional parameter
ALL
is specified.'
say 'Equal files found in
<dir2>
are deleted and notified if the optional'
say ' parameter
DELETE
is specified.'
say 'A list of all the directories recovered by the patterns is automatically'
say ' typed. This can be prevented if the optional parameter
NODL
is specified.'
say 'All directories scanned and all pairs of equal files detected are stored in'
say ' the files
T:EqFiles_DList1
,
T:EqFiles_DList2
, and
T:EqFiles_Result
. The'
say ' optional parameter
FILES
prevents their deletion on exit.'
say 'The optional parameter
SIZE>x
, where
x
is a positive integer, prevents'
say ' comparisons between files with size lower than, or equal to,
x
.'
say 'The optional parameters
INPAT=y
and/or
EXPAT=z
, where
y
and
z
must be legal'
say ' AmigaDOS patterns, can be used to select and/or reject all files whose'
say ' filenames match the patterns.'
say 'By default, icons are never compared unless the optional parameter
ICONS
'
say ' is specified.E p'
exit